package com.t2c.tibetantochinese.home;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.View;

import com.t2c.tibetantochinese.R;
import com.t2c.tibetantochinese.base.BaseFragment;
import com.t2c.tibetantochinese.realmModel.Phrase;

/**
 * Created by zoulu on 16/6/18.
 * homepage
 */
public class HomeFragment extends BaseFragment{


    @Override
    protected int getContentViewResId() {
        return R.layout.home_layout;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {

        super.onViewCreated(view, savedInstanceState);
        switchContent(new HomePage());
    }

    //切换fragment
    public void switchContent(Fragment fragment) {
        FragmentTransaction transaction  = getChildFragmentManager().beginTransaction();
        transaction.addToBackStack(fragment.getTag());
        transaction.replace(R.id.content, fragment).commit(); // 替换Fragment，实现切换
    }
    //切换fragment
    public void switchContent(Fragment fragment,Phrase phrase) {
        FragmentTransaction transaction  = getChildFragmentManager().beginTransaction();
        transaction.addToBackStack(fragment.getTag());
        Bundle bundle = new Bundle();
        bundle.putSerializable("PHRASE",phrase);
        fragment.setArguments(bundle);
        transaction.replace(R.id.content, fragment).commit(); // 替换Fragment，实现切换
    }

    //fragment返回
    public void fragmentBack(){
        getChildFragmentManager().popBackStack();
    }
}

